<?php

namespace App\Model;

use function foo\func;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class RedPacketStream extends Model
{
    protected $connection = 'api';
    protected $table = 'red_packet_stream';
    
    public function getList(Request $request, int $packet_id){
        $limit = $request->input('limit',10);
        $page = $request->input('page',1);
        $query = new self();
        // todo 搜索
        return $query->with(['user','room'])->where('packet_id', $packet_id)->orderBy('id','DESC')->paginate($limit,'*','page',$page);
    }
    
    public function user() {
        return $this->belongsTo(Number::class,'user_id','user_id')->withDefault(['nickname' => '未知']);
    }
    
    public function room() {
        return $this->belongsTo(Room::class,'room_id','room_id')->withDefault(['name' => '未知']);
    }
}
